#include<vector>
#include<iostream>
#include<queue>
using namespace std;

namespace pdd{
class one_4_19_zkm{
public:
    one_4_19_zkm(){
        int n;vector<vector<int>> msgs;
        get_data(n, msgs);
        cout<< solve(n, msgs)<<endl;
    }

    void get_data(int &n, vector<vector<int> > &msgs){
        n = 3;
        msgs = {{1,1,0},{11,2,0},{31,2,0}}; 
    }

    int solve(int n, vector<vector<int>>&msgs){
        queue<int> q;
        int cnts[100001] = {0};
        int ans = 0;
        for(int i = 0; i < n; i++){
            while(!q.empty()&&msgs[i][0]-msgs[q.front()][0]>30){
                cnts[msgs[q.front()][1]]--;
                q.pop();
            }
            if(msgs[i][2]==1){
                ++ans;
                cnts[msgs[i][1]]++;
                q.push(i);
            }else{
                if(!q.empty()&&msgs[i][0]-msgs[q.back()][0]<=10)continue;
                if(cnts[msgs[i][1]]>0)continue;
                ++ans;
                cnts[msgs[i][1]]++;
                q.push(i);
            }
        }
        return ans;
    }
};
}